package etc.com.market;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TextView;

public class StoreTopPage extends Activity implements OnItemClickListener {
	/** Called when the activity is first created. */
	private static final int REQUEST_CODE = 10;
	private ListView lv;
	ArrayList<String> arrtext = new ArrayList<String>();
	int[] idimage = new int[7];
	String str;
	View view;
	String storeId;
	Handler HomeHandler = new Handler();
	boolean homeClicked = false;
	boolean specifyClicked = false;
	boolean searchClicked = false;
	boolean infoClicked = false;
	boolean contactClicked = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.storetoppage);
		lv = (ListView) findViewById(R.id.listview);
		lv.setTextFilterEnabled(true);
		lv.setOnItemClickListener(this);
		lv.setAdapter(new ImageAdapter(this));
		Bundle extras = getIntent().getExtras();
		if (extras == null) {
			return;
		}
		String messageReceive = extras.getString("message");
		String storeID = extras.getString("storeId");
		if(storeID != null){
			this.storeId = storeID;
		}
		if (messageReceive != null) {
			// arrtext.add(messageReceive);
			str = messageReceive.toString();
			
			TextView view = (TextView) findViewById(R.id.storename);
			view.setText(str);
		}
		arrtext.add("おすすめ");
		arrtext.add("カテゴリーから選択");
		arrtext.add("特集");
		arrtext.add("お知らせ");
		arrtext.add("ご要望・お問い合わせ");
		

//        lv.setOnItemClickListener(new OnItemClickListener() {
//			public void onItemClick(AdapterView<?> parent, View view,
//					int position, long id) {
//				// When clicked, show a toast with the TextView text
//				onClick(view, ("店舗詳細;"+  str));
//			}
//		});
	}
	
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		// Toast.makeText(this, "CHON:"+arg2, Toast.LENGTH_SHORT).show();
		// Intent activity2 = new Intent(this, activity2.class);
		// startActivity(activity2);
		
		if 
		(arg2 == 0) {
			onClickRecommend(view, ("店舗詳細;"+  str));

		}else if (arg2 == 1) {
			onClickSearch(view, ("店舗詳細;"+  str));

		} else if (arg2 == 2) {
			onClick(view, ("店舗詳細;"+  str));

		}else if (arg2 == 3) {
			onClickInfo(view, (str));

		}else if (arg2 == 4) {
			onClickContact(view, (str));

		}

	}
	
	// function use for footer button ==============================
	public void Previous(View view) {
//		onClickPre(view, ("Store List;"+  str));
		finish();
		overridePendingTransition(R.anim.fadein,
                R.anim.fadeout);
	}
	
	
	
	@Override
	public void onBackPressed() {
		Previous(new View(this));
	}

	public void Home(View view) {

	}
	

	

	public void SearchProduct(View view) {
		onClickSearch(view, ("Store List;"+  str));
	}
	
	public void SpecifyProduct(View view) {
		onClickSpec(view, ("Store List;"+  str));
	}
	
	public void Info(View view) {
		onClickInfo(view, ( str));
	}
	
	public void Contact(View view) {
		onClickContact(view, ( str));
	}
	
	public void Recommend(View view) {
		onClickRecommend(view, ( str));
	}
   //===================================================================
	
	 public void onClick(View view, String message) {
			Intent i = new Intent(this, ListitemActivity.class);
			i.putExtra("message", message);
			i.putExtra("storeId", storeId);
			// Set the request code to any code you like, you can identify the
			// callback via this code
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);

		}
	 
	 public void onClickPre(View view, String message) {
			Intent i = new Intent(this, StoreListAct.class);
			i.putExtra("message", message);
			// Set the request code to any code you like, you can identify the
			// callback via this code
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);

		}
	 
	 public void onClickInfo(View view, String message) {
			Intent i = new Intent(this, InfomationAct.class);
			i.putExtra("message", message);
			// Set the request code to any code you like, you can identify the
			// callback via this code
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);

		}
	 public void onClickSpec(View view, String message) {
			Intent i = new Intent(this, ListitemActivity.class);
			i.putExtra("message", message);
			i.putExtra("storeId", storeId);
			specifyClicked = true;
			// Set the request code to any code you like, you can identify the
			// callback via this code
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);

		}
	 
	 public void onClickSearch(View view, String message) {
			Intent i = new Intent(this, SearchOursProducts.class);
			i.putExtra("message", message);
			i.putExtra("storeId", storeId);
			searchClicked = true;
			// Set the request code to any code you like, you can identify the
			// callback via this code
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);
		}
	
	 public void onClickContact(View view, String message) {
			Intent i = new Intent(this, SenmailActivity.class);
			i.putExtra("message", message);
			// Set the request code to any code you like, you can identify the
			// callback via this code
			contactClicked = true;
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);
		}
	 
	 
	 public void onClickRecommend(View view, String message) {
			Intent i = new Intent(this, RecommendAct.class);
			i.putExtra("storeId", storeId);
			i.putExtra("message", message);
			// Set the request code to any code you like, you can identify the
			// callback via this code
			startActivity(i);
			overridePendingTransition(R.anim.fadein,
	                R.anim.fadeout);

		}
	 
	public class ImageAdapter extends BaseAdapter {
		private Context mContext;

		public ImageAdapter(Context c) {
			mContext = c;
		}

		public int getCount() {
			return arrtext.size();
		}

		public Object getItem(int position) {
			return null;
		}

		public long getItemId(int position) {
			return 0;
		}

		// create a new ImageView for each item referenced by the Adapter
		public View getView(int position, View convertView, ViewGroup parent) {
			LayoutInflater inflater = LayoutInflater.from(mContext);

			View row = inflater.inflate(R.layout.category, parent, false);

			TextView label = (TextView) row.findViewById(R.id.namefile);
//			ImageView icon = (ImageView) row.findViewById(R.id.icondetail);

			label.setText(arrtext.get(position));
//			icon.setImageResource(idimage[position]);
//			icon.getLayoutParams().height = 36;
//			icon.getLayoutParams().width = 48;
			return row;
		}
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		return super.dispatchTouchEvent(ev);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}
	
}
